package cn.highedu.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
// @Aspect
public class LoggerAspect {
    private static final Logger logger = LoggerFactory.getLogger(LoggerAspect.class);

    /**
     * 对所有的业务方法进行日志记录
     */
    @Before("execution(* cn.highedu.service.UserService.*(..)) || " +
            "execution(* cn.highedu.service.AwardService.*(..))")
    public void log(JoinPoint joinPoint){
        logger.debug("执行了{}方法1", joinPoint.getSignature().getName());
    }

    /**
     * 对所有的业务方法进行日志记录
     * 使用Pointcut ID简化切入点表达式
     */
    @Before("cn.highedu.aspect.Pointcuts.allService()")
    public void log2(JoinPoint joinPoint){
        logger.debug("执行了{}方法2", joinPoint.getSignature().getName());
    }

}

